var EpgFilter=Class.create(EpgWidget,{
	initialize:function($super, id, opts,links) {
        $super(id,opts,links);
        this.c_index = 0;
        this.layout = epgPage.layouts[opts.layout];
        for(var i =0;i<opts.groups.length;i++){
        	var grpName = this.opts.groups[i].name;
        	this.opts.groups[i]['links']=this.initGroupLink(grpName);
        	this.opts.groups[i].current = this.opts.groups[i]['links'][0].id;
     		$("#"+this.opts.groups[i].current+ this.opts.subfix).addClass(this.opts.focusClass);   
        }
    },
    initGroupLink:function(grp){
    	var result = new Array();
    	for(var i=0;i<this.layout.links.length;i++){
    		var aLink = this.layout.links[i];
    		if(aLink.id.indexOf(grp)>=0){
    			result.push(aLink);
    		}
    	}
    	return result;
    },
    findGroupByLink:function(id){
    	var result = new Array();
    	for(var i=0;i<this.opts.groups.length;i++){
    		var aLinks = this.opts.groups[i]["links"];
    		for(var j=0;j<aLinks.length;j++){
    			if(aLinks[j].id==id){
    				return this.opts.groups[i];
    			}
    		}
    	}
    },
    onkeypress:function(evt){
    	aLink = evt.target;
    	group = this.findGroupByLink(aLink.id);
    	if(typeof(group) == 'undefined'){
    		return;
    	}
    	switch(evt.which){
    	 case KEY_ENUM.KEY_OK:
    		var aLinks = group["links"];
      		for(var j=0;j<aLinks.length;j++){
      		 $("#"+aLinks[j].id+ this.opts.subfix).removeClass(this.opts.focusClass);
      		}
    	    $("#"+aLink.id+ this.opts.subfix).addClass(this.opts.focusClass);
    		group.current = aLink.id;    		
    	}
    	return false;
    },
    resetFilter:function (){
     	for(var i=0;i<this.opts.groups.length;i++){
     		var aLinks = this.opts.groups[i]["links"];
     		for(var j=0;j<aLinks.length;j++){
     		 $("#"+aLinks[j].id+ this.opts.subfix).removeClass(this.opts.focusClass);
     		}
     		this.opts.groups[i].current = aLinks[0].id;
     		$("#"+aLinks[0].id+ this.opts.subfix).addClass(this.opts.focusClass);     		
    	}
	 },
	 restoreFilterfocus:function (ids){
	     	for(var i=0;i<ids.length;i++){
	     		var fid = ids[i]; 
	     		var aLinks = this.opts.groups[i]["links"];
	     		if(fid!="" && fid!="-1" && fid!="undefined"){
	     			for(var j=0;j<aLinks.length;j++){
	     	     		 $("#"+aLinks[j].id+ this.opts.subfix).removeClass(this.opts.focusClass);
	     	        }
	     			this.opts.groups[i].current = aLinks[parseInt(fid)+1].id;
	     			if(i==ids.length-1){
	     				this.current = this.opts.groups[i].current;
	     			}
	     			$("#"+aLinks[parseInt(fid)+1].id+ this.opts.subfix).addClass(this.opts.focusClass);   
	     		}else{
	     			this.opts.groups[i].current = aLinks[0].id;	
	     		}
	     	}
	}
});